<#include "/common/_layout.html"/>
<@layout>
	<style>

	</style>
	<div id="app">
		<el-form ref="form" :rules="rules" :model="form" label-width="100px" v-loading="loading">
			<el-form-item label="原密码" prop="oldPwd">
				<el-input type="password" v-model.trim="form.oldPwd" placeholder="请输入原密码"></el-input>
			</el-form-item>
			<el-form-item label="新密码" prop="newPwd">
				<el-input type="password" v-model.trim="form.newPwd" placeholder="请输入新密码"></el-input>
			</el-form-item>
			<el-form-item label="确认密码" prop="newPwd2">
				<el-input type="password" v-model.trim="form.newPwd2" placeholder="请再次确认密码"></el-input>
			</el-form-item>
		</el-form>

		<el-row class="lb_form_button">
			<el-button type="primary" @click="submitForm('form')">提交</el-button>
			<el-button type="danger" @click="closeDlalog">关闭</el-button>
		</el-row>
	</div>

	<script type="text/javascript">
		var _vue = new Vue({
			el: '#app',
			data: function() {
				return {
					form: {
						oldPwd: "",
						newPwd: "",
						newPwd2: ""
					},
					rules: {
						oldPwd: [{
							required: true,
							message: '请输入原密码',
							trigger: 'blur'
						}],
						newPwd: [{
							required: true,
							message: '请输入新密码',
							trigger: 'blur'
						}, {
							min: 6,
							message: '不能小于6位',
							trigger: 'blur'
						}],
						newPwd2: [{
							required: true,
							message: '请确认新密码',
							trigger: 'blur'
						}, {
							validator: function(rule, value, callback) {
								if(value === '') {
									callback(new Error('请再次输入密码'));
								} else if(value !== _vue.form.newPwd) {
									callback(new Error('两次输入密码不一致!'));
								} else {
									callback();
								}
							},
							trigger: 'blur'
						}]
					},
					loading: false
				}
			},
			methods: {
				submitForm: function(formName) {
					var params = {
						"oldPwd": this[formName].oldPwd,
						"newPwd": this[formName].newPwd,
						"newPwd2": this[formName].newPwd2
					};
					var _that = this;
					FormUtils.submit(this, formName, "${ctx}/user/doModifyPwd", params, function() {}, function(data) {
						_that.loading = false;
						if(data.status == 0) {
							parent._vue.$message({
								message: "修改成功",
								type: 'success'
							});
							//关闭弹出框
							_that.closeDlalog();
						} else {
							_that.$message({
								message: data.msg,
								type: 'error'
							});
						}
					});
				},
				closeDlalog: function() {
					parent._vue[window.frameElement.id].dialogVisible = false;
				}
			},
			mounted: function() {}
		});
	</script>
</@layout>